/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package jogopoo.Interface;

import Engine.Fisica.Clip;
import java.awt.AlphaComposite;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JButton;
import javax.swing.JPanel;

/**
 *Classe do Painel do Ranking
 * @author i
 */
public class RankingPanel extends JPanel implements ActionListener{

    public RankingPanel(Ranking rkg) {
        sprite = new Image[1];
        URL url = Clip.class.getResource("/imagens/spaceInvaders.jpg");
        sprite[0] = Toolkit.getDefaultToolkit().getImage(url);
        this.rkg = rkg;

        PBotao = new JPanel();

        this.setLayout(new BorderLayout());
        this.add(PBotao,BorderLayout.SOUTH);

        sair = new JButton("SAIR");
        voltar = new JButton("VOLTAR");

        PBotao.add(voltar);
        PBotao.add(sair);

        sair.addActionListener(this);
        voltar.addActionListener(this);

    }

    @Override
    protected void paintComponent(Graphics cena) {
        super.paintComponent(cena);
        Graphics2D cena2 = (Graphics2D) cena;
        cena2.drawImage(sprite[0], 0, 0, this);
        cena2.setColor(Color.white);
        float alpha = .5f;
        cena2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));
        cena2.fillRect(0, 0, 800, 598);
        cena2.setColor(Color.red);

        cena2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1));
        Font f = new Font("SunsSerif", Font.BOLD, 20);
        cena2.setFont(f);
        cena2.drawString("HIGH SCORE", 200, 50);
        for (int i = 0; i < 5; ++i) {
            cena2.drawString(rkg.getVetorNomes()[i], 100, 100 + 30 * (i + 1));
            cena2.drawString(rkg.getVetorScores()[i], 350, 100 + 30 * (i + 1));
        }
    }


    private Image[] sprite;
    private Ranking rkg;
    private JPanel PBotao;
    private JButton sair;
    private JButton voltar;

    public void actionPerformed(ActionEvent e) {
        Object source = e.getSource();

        if(source == voltar){
            Menu jp = null;
            try {
                jp = new Menu();
            } catch (InterruptedException ex) {
                Logger.getLogger(RankingPanel.class.getName()).log(Level.SEVERE, null, ex);
            }
            jp.setVisible(true);
            rkg.dispose();
        }else if(source == sair){
            System.exit(0);
        }
    }
}
